package com.zlyx.easy.core.list;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import com.alibaba.fastjson.JSON;
import com.zlyx.easy.core.list.EasyList;

/**
 * @author 赵光
 * @desc List封装类
 * @Date 2018年11月27日 上午8:53:39
 */
public class EasyList<E> extends ArrayList<E> {

	private static final long serialVersionUID = 1L;

	public EasyList() {

	}

	public EasyList(Collection<E> c) {
		if (c != null) {
			this.addAll(c);
		}
	}

	@SuppressWarnings("unchecked")
	public EasyList<E> addValue(E... es) {
		this.addAll(Arrays.asList(es));
		return this;
	}

	public boolean without(Object o) {
		return !contains(o);
	}

	public boolean isNotEmpty() {
		return !isEmpty();
	}

	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}

	@SuppressWarnings("unchecked")
	public E[] toArray(Class<E> cls) {
		return toArray((E[]) Array.newInstance(cls, size()));
	}

	public static <E> EasyList<E> newList() {
		return new EasyList<>();
	}

	@SuppressWarnings("unchecked")
	public static <E> EasyList<E> newList(E... es) {
		return new EasyList<E>().addValue(es);
	}

	public static <E> EasyList<E> newList(Collection<E> list) {
		return new EasyList<E>(list);
	}

}
